<!-- Dom模板 -->
<template>
  <div
    class="ATbox"
    ref="waiceng"
    @touchstart="touchstart"
    @touchend="touchend"
  >
    <div class="Author_move" ref="neiceng">
      
      <div
        class="ATitem"
        v-for="(item, index) in $store.state.social.ordinary"
        :key="index"
        ref="ATitem"
        @touchstart="touchOption"
        @touchend="touchendOption"
      >
        <div class="ATheader">
          <div><img :src="item.user_img===null?'../../../static/img/touxiang.jpg':item.user_img" /></div>
          <div class="ATwriter">
            <div>{{ item.name }}</div>
            <div></div>
          </div>
          <div>
            <button  v-if="userId===item.userid?false:true">+关注</button>
          </div>
        </div>
        <div class="ATmoods">{{ item.datatext }}</div>
        <div class="ATimg" ref="ATimg" v-if="item.img_urlo==='null'?false:true" @click="scaleImg">
          <span :class="item.img_urlt==='null'?'ATimgBox':'ATimgBox2'"><img :src="item.img_urlo"/></span>
          <span v-if="item.img_urlt==='null'?false:true" :class="item.img_urlt==='null'?'ATimgBox':'ATimgBox2'"><img :src="item.img_urlt"/></span>
          <span v-if="item.img_urls==='null'?false:true" :class="item.img_urlt==='null'?'ATimgBox':'ATimgBox2'"><img :src="item.img_urls" /></span>
          <span v-if="item.img_urlf==='null'?false:true" :class="item.img_urlt==='null'?'ATimgBox':'ATimgBox2'"><img :src="item.img_urlf" /></span>
        </div>
        <div class="ATperson">
          <div>{{ item.give_num ===""?0:100}}人赞过</div>
          <div>{{ item.circletime }}</div>
        </div>
        <div class="ATlike" v-if="userId===item.userid?false:true">
          <div class="ATpublish">
            <div><img src="../../../static/img/v2_qsomk4.jpg" /></div>
            <div>评论一下</div>
          </div>
          <div><span class="iconfont icon-zan1"></span></div>
          <div><span class="iconfont icon-zhuanfa"></span></div>
        </div>
      </div>

      <div class="loding iconfont icon-jiazai" ref="loding"></div>
    </div>
    <div class="addOption" ref="add" @click="option">
      <i class="iconfont icon-jia"></i>
    </div>
    <div class="pictures" ref="pictures" @click="picOption">
      <i class="iconfont icon-jishiben"></i>
    </div>
    <div class="article" ref="article" @click="artOption">
      <i class="iconfont icon-xiangji"></i>
    </div>
    <div class="videos" ref="videos" @click="vidOption">
      <i class="iconfont icon-shexiangji"></i>
    </div>
    
    <Release v-if="release" class="rele" @close="close" ref="rele"/>
    <div class="imgAlert" ref="imgAlert" v-if="imgAlertFlag"  @click="closeImg">
      
      <span class="zwSpan">
        <span class="zwSpan"><img src="" alt="" ref="IMG"></span>
        
      </span>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
import minxins from "./socialMixin.js";
import sendMixin from "./sendMixin.js"
import Release from './release/release.vue'
export default {
  name: "",
  components:{
    Release
  },
  mixins: [minxins,sendMixin],
  data() {
    return {
      msg: "测试",
      arr: [],
      Pages: 2,
      x: "",
      opt: false,
      timer:null,
      release:false,
      imgAlertFlag:false,
      userId:sessionStorage.getItem('userId')
    };
  },

  // 生命周期 - 创建完成（访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    this.$store.dispatch("social/getData",{type:'0'});
    this.$refs['loding'].style.top=this.diffY-58+'px'
  },
  // Vue方法定义
  methods: {
    scaleImg(e){
      
      if(e.target.nodeName==='IMG'){
        this.imgAlertFlag=true
        
        console.log(9)
        this.$nextTick(()=>{
          this.$refs['IMG'].src=e.target.src
          setTimeout(() => {
            this.$refs['imgAlert'].style.opacity='1'
          }, 200);
        })
        
      }
    },
    closeImg(){
      this.$refs['imgAlert'].style.opacity='0'
      setTimeout(() => {
        this.imgAlertFlag=false
      }, 200);
    },
    
    artOption(){
      
      
    },
    vidOption(){

    },
    close(res){
      
      this.$refs['rele'].$el.style.top=100+'vh'
      setTimeout(() => {
        this.release=res
      }, 400);
    },
    touchend() {
        console.log(this.$refs['loding'])
        if(window.screen.height<=1366&&window.screen.height>812){
          console.log('这是平板')
          if(this.$refs["waiceng"].scrollTop === 0 && this.flag&&this.diffY>150){
            console.log('正在刷新')
            this.$refs["neiceng"].style.transition='all 0.1s linear';
            this.$refs["neiceng"].style.transform = `translateY(60px)`;
            this.$refs["loding"].classList.add('anim_loding');
            setTimeout(() => {
              this.$store.dispatch("social/getData",{type:'1'}).then(res=>{
              console.log(res)
              if(res.code===200){
                console.log('刷新成功')
                this.$refs["neiceng"].style.transition='all 0.1s linear';
                this.$refs["neiceng"].style.transform = `translateY(0)`;
                this.$refs["loding"].classList.remove('anim_loding');
                Toast('刷新成功')
                this.diffY=0
              }else{
                Toast('刷新失败')
              }
            });
            }, 100);
          }
          else if(this.$refs['waiceng'].scrollHeight-this.$refs['waiceng'].scrollTop<=1150&&this.flag&&Math.abs(this.diffY)>100){
            Toast.loading({
              message: '加载中...',
              forbidClick: true,
              duration: 50000,
              forbidClick: true
            });
        this.timer=setInterval(() => {
          this.n++
        },1000);    
        setTimeout(() => {
          this.$store.commit('social/changePages',4)
          this.x= this.$store.state.social.Pages
        }, 1500);
        
        }else{
          this.$refs["neiceng"].style.transition='all 0.1s linear'
        this.$refs["neiceng"].style.transform = `translateY(0)`;
        this.diffY=0
        }
        }else{
          console.log('这是移动设备')
          //下拉刷新
          if(this.$refs["waiceng"].scrollTop === 0 && this.flag&&this.diffY>150){
            console.log('正在刷新')

            this.$refs["neiceng"].style.transition='all 0.1s linear'
            this.$refs["neiceng"].style.transform = `translateY(60px)`;
            this.$refs["loding"].classList.add('anim_loding');
            setTimeout(() => {
              this.$store.dispatch("social/getData",{type:'0'}).then(res=>{
              console.log(res)
              if(res.code===200){
                console.log('刷新成功')
                this.$refs["neiceng"].style.transition='all 0.1s linear'
                this.$refs["neiceng"].style.transform = `translateY(0)`;
                this.$refs["loding"].classList.remove('anim_loding');
                Toast('刷新成功');
                this.diffY=0;
              }else{
                Toast('刷新失败')
              }
            });
            }, 1000);
          }
          //上拉加载
          else if(this.$refs['waiceng'].scrollHeight-this.$refs['waiceng'].scrollTop<=661&&this.flag&&Math.abs(this.diffY)>100){

            Toast.loading({
              message: '加载中...',
              forbidClick: true,
              duration: 50000,
              forbidClick: true
            });
        this.timer=setInterval(() => {
          this.n++
        },1000);    
        setTimeout(() => {
          this.$store.commit('social/changePages',4)
          this.x= this.$store.state.social.Pages
        }, 1500);
        this.$refs["neiceng"].style.transition='all 0.1s linear'
        this.$refs["neiceng"].style.transform = `translateY(0)`;
        this.diffY=0
        }
        else{
          this.$refs["neiceng"].style.transition='all 0.1s linear'
        this.$refs["neiceng"].style.transform = `translateY(0)`;
        this.diffY=0
        }
        }
        
        
        this.arr=[]
        this.$refs["neiceng"].removeEventListener("touchstart", this.touchstart);
        this.$refs["neiceng"].removeEventListener("touchmove", this.touchstart)
      }
  },
};
</script>

<style scoped>
/* @import url(''); 引入css类 */
@import url("../../../static/fonts/iconfont.css");
.loding{
  width: .9rem;
  height: .9rem;
  line-height: .7.5rem;
  border-radius: 50%;
  box-shadow: 2px 2px 4px 2px rgba(0, 0, 0, 0.1);
  position: absolute;
  left: calc(50vw - .5rem);
  color: rgb(121, 121, 121);
  text-align: center;
  font-size: .64rem !important;
  padding: .08rem;
}
.anim_loding{
  animation: anim_rotate .8s linear infinite both;;
}
@keyframes anim_rotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}
.imgAlert{
  position: fixed;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 60;
display:table;
text-align:center;
opacity: 0;
transition: all .25s ease-in-out;
}
.zwSpan{
  display:table-cell;
vertical-align:middle;
}
.imgAlert img{
  width: 100vw;
}
.rele{
  width: 100vw;
    height: 100vh;
    background: white;
    position: fixed;
    left: 0;
    top: 100vh;
    z-index: 60;
    transition: all 0.4s ease-in-out;
}
.pictures,
.article,
.videos {
  position: fixed;
  height: 1rem;
  width: 1rem;
  top: 83%;
  left: 83%;
  text-align: center;
  border-radius: 50%;
  box-shadow: 2px 2px 2px 0px rgba(0, 0, 0, 0.2);
  line-height: 1rem;
  background: rgb(255, 255, 255);
  color: rgb(148, 148, 148);
  transition: all 0.2s linear;
  z-index: 50;
  opacity: 0;
}
.iconfont{
  font-size: .48rem;
}
.addOption {
  position: fixed;
  height: 1rem;
  width: 1rem;
  top: 83%;
  left: 83%;
  text-align: center;
  border-radius: 50%;
  box-shadow: 2px 2px 2px 0px rgba(250, 70, 121, 0.1);
  transform: scale(1.3);
  line-height: 1rem;
  background: rgb(250, 70, 121);
  color: white;
  transition: all 0.2s linear;
  z-index: 55;
}
.ATbox {
  /* background-color: rgb(253, 252, 252); */
  width: 100vw;
  height: calc(100vh - 4.03rem);
  overflow-y: auto;
}

.Author_move {
  width: 100vw;
  min-height: 10.666667rem;
  background: white;
  position: relative;
}
.ATitem {
  /* margin-top: 10px; */
  margin: 10px auto 0;
  width: 95%;
  min-height: 6.64rem;
  line-height: 0.533333rem;
  border-radius: 0.266667rem;
  padding: 0.48rem 0.4rem .5rem;
  box-shadow: 0px 2px 19px 0px rgba(0, 0, 0, 0.08);
  background: white;
}

.ATheader {
  display: flex;
  justify-content: space-between;
}
.ATheader > div:nth-child(1) img {
  width: 1.226667rem;
  height: 1.226667rem;
  border-radius: 50%;
}
.ATitem > div:nth-child(2) {
  width: 86%;
  height: 1.066667rem;
  color: rgba(16, 16, 16, 100);
  font-size: 0.426667rem;
  text-align: left;
  margin-top: 0.186667rem;
  font-family: PingFangSC-regular;
}
.ATwriter {
  margin-left: 0.266667rem;
}
.ATwriter > div:nth-child(1) {
  max-width: 3.466667rem;
  min-width: 0.64rem;
  height: 0.693333rem;
  color: rgba(0, 0, 0, 1);
  font-size: 0.48rem;
  line-height: 0.693333rem;
  font-family: PingFangSC-regular;
}
.ATwriter > div:nth-child(2) {
  width: 4.266667rem;
  height: 0.48rem;
  line-height: 0.48rem;
  color: rgba(160, 160, 160, 100);
  font-size: 0.32rem;
  text-align: left;
  font-family: PingFangSC-regular;
}
.ATheader > div:nth-child(3) {
  margin-left: 1.066667rem;
  margin-top: 0.186667rem;
}
.ATheader > div:nth-child(3) button {
  width: 1.706667rem;
  height: 0.746667rem;
  line-height: 0.533333rem;
  border-radius: 0.72rem;
  background-color: rgba(255, 255, 255, 1);
  text-align: center;
  border: 1px solid rgba(243, 58, 101, 1);
  color: rgba(243, 58, 101, 100);
  font-size: 0.373333rem;
  font-family: PingFangSC-regular;
}
.ATimg {
  text-align: center;
  display: flex;
  box-sizing: border-box;
  flex-wrap: wrap;
  height: 4.8rem;
  overflow: hidden;
  border-radius: 0.16rem;
}
.ATimgBox{
  width: 100%;
  height: 4.8rem;
  margin: 0.32rem 0;
  border-radius: 0.16rem;
  overflow: hidden; 
}
.ATimgBox2{
  max-width: 30%;
  margin: 0.11rem  0.11rem;
  border-radius: 0.16rem;
  overflow: hidden; 
  height: 48%;
}
.ATimg img {
  width: 9rem; 

}
.ATperson {
  width: 95%;
  display: flex;
  margin: 10px auto;
  justify-content: space-between;
}
.ATperson > div:nth-child(1) {
  color: #9e9e9e;
  font-size: 14px;
  font-family: PingFangSC-regular;
}
.ATperson > div:nth-child(2) {
  color: #9e9e9e;
  font-size: 13px;
  font-family: PingFangSC-regular;
}
.ATtransmit {
  width: 100%;
  height: 1.786667rem;
  line-height: 0.533333rem;
  border-radius: 0.213333rem;
  display: flex;
  justify-content: space-around;
  padding: 0.186667rem 0.533333rem;
  margin: 0.32rem auto 0;
  background-color: rgba(218, 222, 228, 0.3);
}
.ATtransmit > div:nth-child(1) img {
  width: 1.066667rem;
  height: 1.44rem;
  border-radius: 4px;
}
.ATitlt {
  margin-left: 0.533333rem;
  margin-top: 0.133333rem;
}
.ATitlt > div:nth-child(1) {
  width: 3.013333rem;
  height: 0.613333rem;
  color: rgba(0, 0, 0, 1);
  font-size: 0.426667rem;
  text-align: left;
  font-family: PingFangSC-regular;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ATitlt > div:nth-child(2) {
  width: 5.2rem;
  height: 0.48rem;
  color: rgba(175, 175, 175, 1);
  font-size: 0.32rem;
  text-align: left;
  font-family: PingFangSC-regular;
  /* , */

  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ATtransmit > div:nth-child(3) {
  margin-top: 0.266667rem;
}
.ATtransmit > div:nth-child(3) span {
  width: 0.853333rem;
  height: 0.853333rem;
  border-radius: 50%;
  display: inline-block;
  line-height: 0.853333rem;
  text-align: center;
  background-color: rgba(67, 67, 67, 0.28);
  /* background- :url('../../../static/img/v2_qskx9d.png') ; */
  background-image: url("../../../static/img/v2_qskx9d.png");
  background-repeat: no-repeat;
  background-size: 80%;
  background-position: center;
}

.ATcomment {
  margin-top: 0.32rem;
}
.ATcomment > div {
  color: rgba(0, 0, 0, 1);
  font-size: 0.346667rem;
  margin-bottom: 0.106667rem;
  text-align: left;
  font-family: PingFangSC-regular;
  height: 0.586667rem;
}
.ATitem > div:nth-child(7) {
  height: 0.533333rem;
  color: rgba(255, 172, 130, 1);
  font-size: 0.346667rem;
  text-align: left;
  font-family: PingFangSC-regular;
}
.ATitem > div:nth-child(7) span {
  margin-left: 0.08rem;
}
.ATpublish {
  width: 6.586667rem;
  height: 0.853333rem;
  line-height: 0.533333rem;
  border-radius: 1.28rem;
  background-color: rgba(218, 222, 228, 0.21);
  display: flex;
  padding: 0.08rem 0 0.08rem 0.293333rem;
}

.ATpublish > div:nth-child(1) img {
  width: 0.72rem;
  height: 0.693333rem;
  border-radius: 0.8rem;
}
.ATpublish > div:nth-child(2) {
  max-width: 2.16rem;
  min-width: 1.066667rem;
  margin: 0.08rem 0rem 0.106667rem 0.48rem;
  height: 0.48rem;
  color: rgba(122, 122, 122, 100);
  font-size: 0.32rem;
  text-align: left;
  font-family: PingFangSC-regular;
}
/* .ATitem:last-child{
  margin-bottom: 2.666667rem;
} */
/* 评论 */
.ATlike {
  display: flex;
  justify-content: space-between;
  margin-top: 0.333333rem;
}
.ATlike span {
  font-size: 0.48rem;
  display: inline-block;
  margin-top: 0.106667rem;
  color: #565656;
}
</style>